/**
*      author: Y_Yao
*      created: 2024-09-24 15:19:22
**/

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
const int INF = 0x3f3f3f3f;
const int N = 39;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,-1,1};
char nums[N][N][N];
bool vis[N][N][N];
int L,R,C;
int sx,sy,ex,ey;
int ret;

struct node
{
    int x,y,st,time;
};

void bfs()
{
    node start;
    start.x = sx,start.y = sy,start.st = 0,start.time = 0;
    queue<node> q;
    q.push(start);
    vis[start.st][start.x][start.y] = true;

    while(!q.empty())
    {
        auto cur = q.front();
        q.pop();

        int a = cur.x,b = cur.y;
        if(nums[cur.st][a][b] == 'E' && cur.st == L - 1)
        {
            ret = cur.time;
            return; 
        }

        for(int i = 0;i < 4;i++)
        {
            int x = a + dx[i],y = b + dy[i];
            if(x < 0 || x >= R || y < 0 || y >= C || vis[cur.st][x][y] || nums[cur.st][x][y] == '#')
                continue;
            auto newnode = cur;
            newnode.x = x,newnode.y = y;
            newnode.time++;
            if(nums[cur.st][x][y] == 'E' && cur.st == L - 1)//找到最终答案
            {
                ret = newnode.time;
                return;
            }
            else if(nums[cur.st][x][y] == 'E')//找到下一层的入口
            {
                newnode.time++;
                newnode.st++;
                q.push(newnode);
                vis[newnode.st][newnode.x][newnode.y] = true;
            }
            else
            {
                q.push(newnode);
                vis[newnode.st][newnode.x][newnode.y] = true;
            }       
        }
    }
}

void solve()
{
    for(int i = 0; i < L;i++)
        for(int j = 0;j < R;j++)
            for(int k = 0;k < C;k++)
                cin >> nums[i][j][k];
    

    for(int i = 1; i < L;i++)
        for(int j = 0;j < R;j++)
            for(int k = 0;k < C;k++)
                if((nums[i-1][j][k] == nums[i][j][k] && nums[i][j][k] != '#') || (nums[i][j][k] == 'E' && nums[i-1][j][k] == '.'))
                {
                    nums[i-1][j][k] = 'E';
                }
    
    for(int i = 0;i < R;i++)
    {
        for(int j = 0;j < C;j++)
        {
            if(nums[0][i][j] == 'S')
            {
                sx = i;
                sy = j;
            }
            else if(nums[L-1][i][j] == 'E')
            {
                ex = i;
                ey = j;
            }
        }
    }

    // for(int i = 0; i < L;i++)
    // {
    //     for(int j = 0;j < R;j++)
    //     {
    //         for(int k = 0;k < C;k++)
    //         {
    //             cout << nums[i][j][k];
    //         }
    //         cout << endl;
    //     }
    //     cout << endl;
    // }
    //cout << sx << sy << ex << ey << endl;

    bfs();
    if(ret == 0)
        cout << "Trapped!" << endl;
    else cout << "Escaped in " << ret << " minute(s)."<< endl;
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(1)
    {
        cin >> L >> R >> C;
        if(L == 0 && R == 0 && C == 0) break;
        solve();
        ret = 0;
    }
    return 0;
}